<template>
    <div>
        <Modal v-model="groupTransferModal" :mask-closable='false' :width="1140" :styles="{top: '90px'}" :footer-hide="true">
            <div style="margin-top: 20px">
                <rui-page :defines="defines">
                    <Row>
                        <Form inline :label-width="90" class="search-form" style="margin-left:-15px;">
                            <Form-item label="操作组名称">
                                <Input type="text" v-model="searchForm.groupName" clearable placeholder="请输入关键字" style="width: 200px"/>
                            </Form-item>
                            <Form-item style="margin-left:-45px;" class="br">
                                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                            </Form-item>
                        </Form>
                    </Row>
                    <Row>
                        <Button @click="save" type="primary" icon="ios-add">确定</Button>
                    </Row>
                    <rui-table :defineId="'groupTransferInfo'"
                               :select="true"
                               @loadDatas="queryGroup"
                               @on-selection-change="showSelect"
                               ref="groupTransferTable">
                    </rui-table>
                </rui-page>
            </div>
        </Modal>
    </div>
</template>

<script>
    let groupTransferInfo = [
        {
            key: "name",
            title: "操作组名称",
            align: 'center',
        }
    ]
    import {queryGroupName,groupTransfer,getGroupInfo} from  "@/projects/afs-core-business/api/afs-case/parameter-rules/group";
    export default {
        name: "groupTransfer",
        data() {
            return{
                groupTransferModal:false,
                selectCount: 0,
                selectList:[],
                memberInfo:{
                    groupId:"",
                    list:[]
                },
                searchForm:{
                    pageNumber: 1,
                    pageSize: 10,
                    groupName:""
                }
            }
        },
        methods:{
            groupTransferMsg: function (msg) {
                if(msg!==""){
                    this.memberInfo.list = msg;
                    this.groupTransferModal = true;
                    this.queryGroup(1,10);
                }
            },
            showSelect(e) {
                this.selectList = e;
                this.memberInfo.groupId = e[0].id;
                this.selectCount = e.length;
            },
            handleSearch(){
                this.queryGroup(1,10);
            },
            queryGroup(pageNumber, pageSize){
                this.searchForm.pageNumber = pageNumber;
                this.searchForm.pageSize = pageSize;
                getGroupInfo(this.searchForm).then(res=>{
                    if(res.code === "0000"){
                        let {records, total} = res.data;
                        this.$refs.groupTransferTable.updateTableData(records, total);
                    }
                })
            },
            save(){
                if(this.selectCount===1){
                    groupTransfer(this.memberInfo).then(res=>{
                        if(res.code === "0000"){
                            this.$Message.success("转组成功");
                            this.groupTransferModal = false;
                            this.$parent.refreshMember();
                        }
                    })
                }else{
                    this.$Message.warning("请勾选一项数据");
                    return;
                }
            }
        },
        computed: {
            defines() {
                return [
                    {
                        id: 'groupTransferInfo',
                        fields: groupTransferInfo
                    }
                ]
            }
        }
    }
</script>
